using System;
using System.Collections.Generic;
using System.Text;
using SP.Parameter;

namespace SP.HwLowProfileRS
{
    /// <summary>
    /// Rim lighting pixel shader
    /// </summary>
    public class RimLightingVertexFusion : AbstractFusion
    {
        public RimLightingVertexFusion()
        {
            AddParameter(new Vec3Parameter("rimColor")
                .SetX(1)
                .SetY(1)
                .SetZ(1)
                .SetDesc("Rim color, [R, G, B]")
                );

            AddParameter(new ScalarParameter("rimThickness")
                .SetS(0.8f)
                .SetDesc("Rim thickness")
                );
        }

        public override string Name
        {
            get { return "RimLightingVertex"; }
        }

        public override string Desc
        {
            get { return "** REMEMBER TO ENABLE RimLightingPixel!!!!!!!!!!!!!!!!!!!! **.\n Enable this fusion to support rim lighting effect."; }
        }

        public override Stage Stage
        {
            get { return Stage.Vertex0; }
        }

        public override int UVChannelCount
        {
            get { return 0; }
        }

        public override void Code(StringBuilder b, string platform)
        {
            AddLine(b, "float Rim = 1 - saturate(dot(pipeline.N_Ws, pipeline.VDir_Ws));");
            AddLine(b, "Rim = smoothstep(1 - float(rimThickness), 1, Rim);");
            AddLine(b, "pipeline.Rim = vec4(rimColor, Rim);");
        }
    }

    /// <summary>
    /// Rim lighting pixel shader
    /// </summary>
    public class RimLightingPixelFusion : AbstractFusion
    {
        public RimLightingPixelFusion()
        {
        }

        public override string Name
        {
            get { return "RimLightingPixel"; }
        }

        public override string Desc
        {
            get { return "** REMEMBER TO ENABLE RimLightingVertex!!!!!!!!!!!!!!!!!!!! **.\n Enable this fusion to support rim lighting effect."; }
        }

        public override Stage Stage
        {
            get { return Stage.Override; }
        }

        public override int UVChannelCount
        {
            get { return 0; }
        }

        public override void Code(StringBuilder b, string platform)
        {
            AddLine(b, "pipeline.FragColor = lerp(pipeline.FragColor, input.Rim.rgb, input.Rim.a);");
        }
    }
}
